<?php
	$mod_name = "index";

	include_once(realpath(dirname(__FILE__).'/../../conf.php'));
	include_once("$GLOBALS[dir_interface]/IModule.php");
	include_once("$GLOBALS[dir_abstract]/AModule.php");
	include_once("$GLOBALS[dir_class]/CCore.php");
	include_once("$GLOBALS[dir_class]/CLayout.php");
	include_once("$GLOBALS[dir_module]/html/MHtml.php");
	include_once("$GLOBALS[dir_module]/menu/MMenu.php");

	class MIndex extends AModule implements IModule
	{
		var $layout;
		private $_window_title;
		private $_css;
		private $_menu;
		private $_body;

		public function __construct($name = "index")
		{
			$this->name = $name;
			$this->_content = "";
		}

		public function __destruct()
		{
		}

		public function inizialize()
		{
			$db = CCore::getDB();
			if(!($res = $db->query("SELECT * FROM gruppo")))
			{
				$this->debug("nessun risultato trovato");
			}
			$this->layout = new CLayout("indexLayout");

			$this->_css = new MHtml("<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\" />");
			$this->_window_title = new MHtml("PHP Framework");
			$this->_body = new MHtml(CDB::printTable($res));

			$this->_menu = new MMenu("dxMenu");
			$this->_menu->inizialize();
		}

		public function run()
		{
			$this->layout->loadLayout("$GLOBALS[dir_module]/index/layout/default.xml");
			$this->layout->instanceGroup("main", "indmain");
			$this->layout->setModule("indmain", "styles", $this->_css);
			$this->layout->setModule("indmain", "title", $this->_window_title);
			$this->layout->setModule("indmain", "lateralMenu", $this->_menu);
			$this->layout->setModule("indmain", "content", $this->_body);
			$this->_menu->run();
		}

		public function display()
		{
			return $this->layout->display();
		}

		public function terminate()
		{
			$this->_menu->terminate();
		}
	}

?>